<template>
	<!-- 首页灵活用工详情页组件 -->
	<view class="main">
		<u-sticky>
			<view class="lgTop">
						
				<view class="selects">
				  <u-icon class="map" name="map"></u-icon>
				  <pickerAddress
				    ref="addr"
					@fnscroll="fnscroll"
				    @fnpickerAddress="fnpickerAddress"
				    class="inp"
				  ></pickerAddress>
				  <u-icon color="#efefef" class="icons" name="arrow-down"></u-icon>
				</view>
			
				<view class="search">
					<u-search :show-action='true' placeholder="请输入工作/工种名称" @custom="search" @search="search" v-model="keyword"></u-search>
				</view>
			</view>
		
		</u-sticky>
		
		<view class="register">
			<view class="item_three" @click="goLinggong">
				<text>我要找工作</text>
			</view>
			<view class="item_three" @click="goGuzhu">
				<text>我要招人</text>
			</view>
			<view class="item_three" @click="gofjyz">
				<text>附近企业</text>
			</view>
		</view>
		
		
		<view class="wrap">
			<!-- <u-swiper :list="list"></u-swiper> -->
			<uni-swiper-dot :info="info" :current="current" field="content" :mode="round">
				<swiper class="swiper-box" @change="change11">
					
					<swiper-item >
						<ul class="swiper-item">
							<li  v-for="item in lgList" @click="goSort(item.name,item.children)">
								<img :src="item.iconUrl" alt="">
								<view class="">{{item.name}}</view>
							</li>
						</ul>
					</swiper-item>
					<!-- <swiper-item >
						<view class="swiper-item">
							临时工
						</view>
					</swiper-item> -->
					
				</swiper>
			</uni-swiper-dot>
		</view>
		
		
		
    <!-- 零工市场首页展示列表 -->
		<view class="hotWork">
			<u-sticky offset-top="80">
			<!-- <view class="title">
				<text>热门岗位</text>
				<view class="line"></view>
				
			</view> -->
			<view class="title">
				<view class="left">
					<view class="tabs" @click="change('热门')">
						<text :class="{'active':type=='热门'}">热门岗位</text>
						<view class="line" v-if="type=='热门'"></view>
					</view>
					
					<view class="tabs" @click="change('附近')">
						<text :class="{'active':type=='附近'}">附近岗位</text>
						<view class="line" v-if="type=='附近'"></view>
					</view>
				</view>
				<view class="right">
					<!-- <u-button type="primary" size="mini">筛选</u-button> -->
				</view>
			</view>
			
			</u-sticky>
			<view style="margin-top: 150rpx;" v-if='lists.length==0'>
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>

			<view class="workItem" v-for="(item,index) in lists" :key="index" @click="goDetil(item.id)">
				<view class="header">
					<text class="name">{{item.work_name}}</text>
					<text class="money">{{item.wages.replace(',', '')}}</text>
				</view>
				<view class="center">
					<!--  -->
					<view class="tags" >
						<u-tag :text="item.create_type" type="primary"  size="mini" style="margin-right: 10px" v-if='item.create_type=="企业"'/>
						<u-tag :text="item.create_type" type="warning"  size="mini" style="margin-right: 10px" v-if='item.create_type=="个人"'/>
						<u-tag :text="item.settlement" type="success" size="mini" style="margin-right: 10px"/>
						<u-tag :text="item.need_num+'人'" type="success"   size="mini" style="margin-right: 10px"/>
						<u-tag :text="item.work_exp== '' || item.work_exp==null ?'无':item.work_exp" type="success"   size="mini" style="margin-right: 10px"/>
					</view>
					<view class="time">
						{{item.add_time.substring(0,10)}}
					</view>
				</view>
				<view class="footer">
					<!-- <text class="address">{{item.city+item.area+item.address}}</text> -->
					<text class="address">{{item.address}}</text>
					
					<text class="add1">
						{{ item.juli<1000?(item.juli || '')+'m':((item.juli/1000).toFixed(2) || '')+'km'}}
					</text>
				</view>
			</view>
			<view style="margin-top: 30rpx;">
				<u-loadmore style="margin-top: 30rpx;" :status="status" />
			</view>
		</view>
    
	</view>
</template>

<script>
	import pickerAddress from "@/components/citys/pickerAddress.vue";
	import api from '@/api/routes.js'
	export default {
		components:{
			pickerAddress,
		},


		data() {
			return {
				page: 1,
				limit: 5,
				status: "loadmore",
				lists: [],
				// 拿到的数据总条数
				total: 0,
				//判断是否发送请求的条件
				load: false,
				type:'热门',

				keyword: '',
				lgList: [],
				
				
				
			};
		},
		onLoad() {
			let that = this
			wx.getLocation({
			 type: 'wgs84',
			 
			 success (res) {
			   that.lat = res.latitude
			   that.lgt= res.longitude
			   that.getList()
			   console.log(res,'lg获取当前位置');
			 }
			})
			this.classification();
			
			
		},
		onShow(){
			this.getMapLocation()  
		},
		onReachBottom() {
			if (this.status === "loadmore") {
				this.loadmore();
			}
		},
		methods: {
			// 判断是否开启定位
			getMapLocation(){
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
					 wx.setStorageSync("nowLat",res.latitude);
					 wx.setStorageSync("nowLgt",res.longitude);
					 },
				 fail() {
					console.log('未拿到经纬度！！');
					uni.showModal({
						title: '提示',
						content: '获取不到当前位置，请打开定位服务功能',
						
					})
				 }
				})
				
			},
		async classification(){
				const res = await this.$myRequest({
					url: api.classificationGrid,
					method: "GET",
					data: {
						parentId:0,
						businessId:3
					},
				});
				if(res.data.code==0){
					this.lgList=res.data.list;
				}
				console.log(this.lgList,'分类！！');
			},
			change11(e) {
					this.current = e.detail.current;
				},
			goSort(index,child){
				console.log(index,"index---")
				let str = ""
				if(child.length>0){
					for(let i=0;i<child.length;i++){
						str+=","+child[i].name;
					}
					str = str.replace(",","")
				}
			
				uni.navigateTo({
					url:"/package/pages/searchJob/other/lgSort?index="+index+"&type="+str,
				})
			},
			change(val){
				let that=this;
				this.type = val
				// 判断是否开启定位
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
				  if(val=="附近"){
				  	that.search(1)
				  }else{
				  	that.search()
				  }
				 },
				 fail() {
				console.log('未拿到经纬度！！');
				uni.showModal({
					title: '提示',
					content: '获取不到当前位置，请打开定位服务功能',
					
				})
				 }
				})
				
			},
			gofjyz(){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/fujinyizhan',
				});
			},
			goDetil(id){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/detils?id='+id+'&type=招工',
				});
			},
			search(val) {
				this.load = false;
				this.page = 1
				this.limit = 5
				this.status = 'loadmore'
				this.lists = []
				this.getList(val)
			},
			loadmore() {
				this.page++;
				this.getList();
			},
			async getList(val) {
				wx.showLoading()
				// 判断当前是否在请求，如果为true正在请求数据，就让他返回空，如果为false没在请求，就让它开始请求数据
				if (this.load) {
					return;
				}
				this.load = true;
				// 请求数据时，状态改为加载中状态
				this.status = "loading";
				const res = await this.$myRequest({
					url: api.lgInfoPageList,
					method: "POST",
					data: {
						page: this.page,
						limit: this.limit,
						"orderSort": 1, //排序方式:1-热门,2-附近
						"key": this.keyword, //搜索关键词,
						"wages": "", //薪资
						"settlement": "", // 结算方式
						"mbId": "", //用户ID, ~~~~传这个值时,代表查询我发布的 ,大多数都不传
						"infoType": "招工", //类型:招工  / 求职  (必传)
						"lgt":this.lgt,
						"lat":this.lat,
						"juli" :val
					},
				});
				
				console.log(res,"热门岗位")
				this.load = false;
				if (res.data.code == 0) {
					// this.lists = res.data.page.list
					this.total = res.data.page.totalCount;
					this.lists = [...this.lists, ...res.data.page.list];
					this.ismore();
					setTimeout(() => {
						wx.hideLoading()
					}, 2000)
				} else {
					wx.showToast({
						title: '查询失败',
						icon: 'none'
					})
				}
				console.log(res.data.page.list,1228800)
			},
			ismore() {
				if (this.total === this.lists.length) {
					this.status = "nomore";
				} else {
					this.status = "loadmore";
				}
			},
			goGuzhu() {
				uni.navigateTo({
					url: '/package/pages/searchJob/other/woshiguzhu',
				});
			},
			goLinggong() {
				uni.navigateTo({
					url: '/package/pages/searchJob/other/woshilinggong',
				});
			},
			lgRegister() {
				console.log("林工登记！！！");
				uni.navigateTo({
					url: '/package/pages/components/lingGonRegister',
				});
			}
		},
	};
</script>

<!-- <style>
/* #ifndef H5 */
page {
  height: 100%;
  background-color: #f2f2f2;
}

/* #endif */
</style> -->

<style lang="scss" scoped>
	.main {
		background: #ffffff;
	}

	.wrap {
		// background: white;
		// border: 1px solid pink;
		width: 94%;
		margin-left: 3%;
	}

	.search {
		background: white;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		padding-left: 10rpx;
		flex: 1;
	}

	.register {
		height: 120rpx;
		background: white;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		// padding-top: 20rpx;
		// padding-bottom: 20rpx;

		.item_three {
			width: 30%;
			height: 80rpx;
			background: #1684fd;
			display: flex;
			align-items: center;
			justify-content: center;
			color: white;
			font-weight: 500;
			font-size: 34rpx;
			;
		}

		.item_three:nth-child(1) {
			background: #1684fd;
			border-radius: 6px;
		}

		.item_three:nth-child(2) {
			background: #16B998;
			border-radius: 6px;

		}

		.item_three:nth-child(3) {
			background: orange;
			border-radius: 6px;

		}

	}

	.hotWork {
		background: white;

		.title{
			font-family: Arial, Helvetica, sans-serif;
			margin-left: 3%;
			display: flex;
			color: #909399;
			justify-content: space-between;
			background: white;
			font-size: 32rpx;
			line-height: 36px;
			.tabs{
				margin-right: 30rpx;
				.line{
					width: 30rpx;
					height: 4px;
					background: #1684fd;
					// background: #000088;
					margin-left: 46rpx;
					// border-radius: 0 0 10rpx 10rpx;
				}
			}
			.active{
				color: #333;
				font-weight: bold;
			}
			.left{
				display: flex;
			}
			.right{
				margin-right: 3%;
			}
		
		}

		.workItem {
			width: 94%;
			margin-left: 3%;
			height: 240rpx;
			border-radius: 6px;
			box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
			margin-top: 20rpx;

			.header {
				height: 90rpx;

				.name {
					color: #333;
					font-size: 34rpx;
					font-weight: bold;
					font-family: Arial, Helvetica, sans-serif;
					 white-space: nowrap;  
					 overflow: hidden;       
					 text-overflow: ellipsis; 
					 width: 70%;
				}

				.money {
					color: #F75E54;
					font-size: 30rpx;
					font-weight: 500;
					font-family: Arial, Helvetica, sans-serif;
				}
			}

			.center {
				height: 75rpx;
				border-bottom: 1px solid #E4E7ED;

				.time {
					color: #000000;
					font-size: 28rpx;
					font-family: Arial, Helvetica, sans-serif;
				}

				.tags {
					display: flex;

					.tagItem {
						font-size: 24rpx;
						margin-right: 15rpx;
						padding: 4rpx 10rpx 4rpx 10rpx;
						border-radius: 2px;
						background: #DBF1E1;
						color: #19BE6B;
					}

				}
			}

			.footer {
				height: 75rpx;

				.address {
					// color: #3d3d3f;
					font-size: 30rpx;
					font-family: Arial, Helvetica, sans-serif;
					width: 80%;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.add1 {
					color: #5B81B8;
					font-size: 28rpx;
					font-family: Arial, Helvetica, sans-serif;
				}
			}

			.header,
			.center,
			.footer {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 96%;
				margin-left: 2%;
			}
		}
	}
		
	.lgTop{
		display: flex;
		justify-content: space-between;
		background: #ffffff;
	}
	.selects {
	  width: 140rpx;
	  margin-right: 20rpx;
	  display: flex;
	  align-items: center;
	  justify-content: space-between;
	  font-size: 13px;
	
	  .map {
	    font-size: 18px;
	    color: #d9d9d9;
	  }
	
	  .inp {
	    width: 90rpx;
	    overflow: hidden;
	    text-overflow: ellipsis;
	    white-space: nowrap;
	  }
	}
	.swiper-item{
		display: flex;
		flex-wrap: wrap;
		
		li{
			display: flex;
			flex-direction: column;	
			justify-content: center;
			align-items: center;
			width: 24%;
			height: 70px;
			// border: 1px solid magenta;
			margin: 0 4px 4px 0;
			img{
				width: 50px;
				height: 50px;
			}
		}
			
		li:nth-child(4),li:nth-child(8),li:nth-child(12){
			margin-right: 0;
		}
	}
</style>
